package com.jiang.daily.Q2241;

/**
 * @author Jiang
 * @version 1.0
 * @date 2025/01/05 1:58
 */
class ATM {
    long[] count;
    long[] money;

    public ATM() {
        count = new long[5];
        money = new long[] { 20, 50, 100, 200, 500 };
    }

    public void deposit(int[] banknotesCount) {
        for (int i = 0; i < 5; i++) {
            count[i] += banknotesCount[i];
        }
    }

    public int[] withdraw(int amount) {
        int[] temp = new int[5];
        for (int i = 4; i >= 0; --i) {
            temp[i] = (int) Math.min(count[i], amount / money[i]);
            amount -= temp[i] * money[i];

            if (amount == 0) {
                for (int j = 0; j < 5; j++) {
                    count[j] -= temp[j];
                }
                return temp;
            }
        }
        return new int[] { -1 };
    }
}